﻿<%@ Page Language="C#" MasterPageFile="~/Site.master" 
    CodeFile="DynamicFilter.aspx.cs" Inherits="ForeignKeyFilter" %>

<%@ Register src="~/DynamicData/Content/GridViewPager.ascx" tagname="GridViewPager" tagprefix="asp" %>

<asp:Content ID="headContent" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true" />

    <h2 class="DDSubHeader">Filtering <%= table.DisplayName%> Rows Using a Specified Foreign-key</h2>
    
     <div class="ExampleView">
	    Dynamic Data creates the UI to filter table rows by using the default 
        filter templates that are in the ~\DynamicData\Filters folder. <br />
	    The default templates support foreign-key, Boolean, and enumeration column types. <br />
        This example uses the 
	    <a href="http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.dynamicfilter(VS.100).aspx" target="_blank">
	    <code>System.Web.DynamicData.DynamicFilter</code></a> control to create the UI for filtering 
        rows by using the specified foreign-key <i>ProductCategory</i>. 
    </div>
    
   <hr />
   
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
                EnableClientScript="true"
                HeaderText="Vui lòng sửa lại các lỗi dưới đây" />
            <asp:DynamicValidator runat="server" ID="GridViewValidator" 
                ControlToValidate="GridView1" Display="None" />
       
            <!-- Set the DynamicFilter control attributes. --> 
            ProductCategogory
            <asp:DynamicFilter runat="server" ID="CategoryFilter" 
            DataField="ProductCategory" FilterUIHint="ForeignKey" 
            OnFilterChanged="OnFilterSelectedIndexChanged" /><br />

            <!-- Data-bound control that shows the filtered table rows. -->
            <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" 
                EnablePersistedSelection="true" PageSize="5" 
                AllowPaging="True" AllowSorting="True" CssClass="DDGridView">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:LinkButton ID="DeleteLinkButton" runat="server" CommandName="Delete"
                                CausesValidation="true" Text="Delete"
                                OnClientClick='return confirm("Are you sure you want to delete this item?");'
                            />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>

                <PagerStyle CssClass="footer"/>        
                <PagerTemplate>
                    <asp:GridViewPager runat="server" />
                </PagerTemplate>
                <EmptyDataTemplate>
                    Chưa có dữ liệu.
                </EmptyDataTemplate>
            </asp:GridView>
            
            <!-- The provider that connects to the database -->
           <asp:EntityDataSource ID="GridDataSource" runat="server" EnableDelete="True" 
            ContextTypeName="AdventureWorksLT_DataModel.AdventureWorksLT_DataEntities" 
            EnableFlattening="False" 
            EntitySetName="Products"  />
        
            
            <!-- The control that handles the details for querying 
            the database, after a user's filtering action -->
            <asp:QueryExtender ID="QueryBlock1" TargetControlID="GridDataSource" 
                runat="server">
                <asp:DynamicFilterExpression ControlID="CategoryFilter" />
            </asp:QueryExtender>
            
        </ContentTemplate>
    </asp:UpdatePanel>
 
</asp:Content>
